package com.atguigu.lease.web.admin.schedule;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author kk
 * #date 2024/6/21 23:36
 */

/*
* 定时任务类
* */
    @Component
public class ScheduledTasks {

        @Autowired
    LeaseAgreementService leaseAgreementService;

    //定时任务: 检查租约是否过期
    // cron 时间表达式(七域表达式)
    /*
     *  秒 分 时 日 月 星期 年
     * */
    // @Scheduled(cron = "* * * * * *")
    public void checkAgreementStatus(){
        LambdaUpdateWrapper<LeaseAgreement> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.lt(LeaseAgreement::getLeaseEndDate, new Date())
                     .set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED);
        leaseAgreementService.update(updateWrapper);
    }
}
